﻿Public Class ProjectManager
    Inherits ObservableImpl
    Implements NamedStatusObservable
    Implements TimeObserver
    Implements Resetable
    Private command As Command
    Private commandQueue As CommandQueue
    Private name As String
    Private status As PMStatus = PMStatus.Idle

    Public Sub New()
        name = "PM"
        commandQueue = New CommandQueue()
    End Sub

    Public Function getName() As String Implements NamedStatusObservable.getName
        Return name
    End Function

    Public Function getStatusDescription() As String Implements NamedStatusObservable.getStatusDescription
        If Not command Is Nothing Then
            Return "Assigning: " + command.getName()
        End If
        If commandQueue.isEmpty Then
            Return "No commands left"
        End If
        Return "Cannot assign Pending Actions yet"
    End Function

    Sub setCommands(ByVal commandList As List(Of Command))
        commandQueue.addCommands(commandList)
    End Sub


    Public Sub timeNotification() Implements TimeObserver.timeNotification
        setNextCommand()
    End Sub


    Private Sub setNextCommand()
        command = commandQueue.popOutNextExecutableCommand()
        If Not command Is Nothing Then
            command.execute()
            status = PMStatus.Idle
        Else
            status = PMStatus.Busy
        End If
        NotifyObservers()
    End Sub

    Public Sub reset() Implements Resetable.reset
        status = PMStatus.Idle
        command = Nothing
        commandQueue = New CommandQueue()
        NotifyObservers()
    End Sub
End Class
